package com.nero.service.impl;

import com.nero.bean.PO.TbItemCat;
import com.nero.bean.PO.TbItemCatExample;
import com.nero.dao.TbItemCatMapper;
import com.nero.service.IItemCatService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Nero on 18/8/10.
 */
@Service
public class ItemCatServiceImpl implements IItemCatService {
    @Resource
    TbItemCatMapper tbItemCatMapper;

    @Override
    public List<TbItemCat> getAll() {
        return tbItemCatMapper.selectByExample(new TbItemCatExample());
    }

    @Override
    public List<TbItemCat> getRoots() {
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo((long)0);
        List<TbItemCat> found =  tbItemCatMapper.selectByExample(example);
        List<TbItemCat> send = new ArrayList<>();
        for (int i = 0; i < 14; i++) {
            send.add(found.get(i));
        }
        return send;
    }
}
